﻿var isFullScreen = false;

function fullScreen(element) {
    if (!isFullScreen) {
        requestFullScreen(element);
        isFullScreen = true;
    } else {
        exitFull();
        isFullScreen = false;
    }
}

function requestFullScreen(element) {
    var requestMethod = element.requestFullScreen || element.webkitRequestFullScreen || element
        .mozRequestFullScreen || element.msRequestFullScreen;
    if (requestMethod) {
        requestMethod.call(element);
    } else if (typeof window.ActiveXObject !== "undefined") {
        var wscript = new ActiveXObject("WScript.Shell");
        if (wscript !== null) {
            wscript.SendKeys("{F11}");
        }
    }

}
//退出全屏
function exitFull() {
    // 判断各种浏览器，找到正确的方法
    var exitMethod = document.exitFullscreen || //W3C
        document.mozCancelFullScreen || //Chrome等
        document.webkitExitFullscreen || //FireFox
        document.webkitExitFullscreen; //IE11
    if (exitMethod) {
        exitMethod.call(document);
    } else if (typeof window.ActiveXObject !== "undefined") { //for Internet Explorer
        var wscript = new ActiveXObject("WScript.Shell");
        if (wscript !== null) {
            wscript.SendKeys("{F11}");
        }
    }
}

function iFrameSize(left_width) {
    var NS = getWindowSize();
    var screenwidth = NS.width;
    var screenheight = NS.height;
    var height = document.body.clientHeight;

    var mainheight = screenheight - 72;

    var fleftwidth = 0;

    if (left_width) {
        fleftwidth = left_width;
    } else {
        if (document.getElementById("fleftdiv").style.display == "none") {
            fleftwidth = 0;
        } else {
            fleftwidth = 235;
        }
    }
    var mainwidth = screenwidth - fleftwidth;
    document.getElementById("fleft") ? document.getElementById("fleft").width = fleftwidth + "px" : null;
    document.getElementById("fmain") ? document.getElementById("fmain").width = mainwidth + "px" : null;
    document.getElementById("fleft") ? document.getElementById("fleft").height = mainheight + "px" : null;
    document.getElementById("fmain") ? document.getElementById("fmain").height = mainheight + "px" : null;

    document.getElementById("otherIframe") ? document.getElementById("otherIframe").width = mainwidth + "px" : null;
    document.getElementById("otherIframe") ? document.getElementById("otherIframe").height = mainheight + "px" : null;
}

//---------------------------页面自适应----------------------------------------------
function getWindowSize() {
    var e = new Object();
    if (window.self && self.innerWidth) {
        e.width = self.innerWidth; //得到火狐，谷歌，欧朋窗口大小
        e.height = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        e.width = document.documentElement.clientWidth; //得到ie6以上窗口大小
        e.height = document.documentElement.clientHeight;
    } else {
        e.width = document.body.clientWidth; //得到ie6以下窗口大小
        e.height = document.body.clientHeight;
    }
    return e;
}


function iFrameHeight() {
    var NS = getWindowSize();
    var screenwidth = NS.width;
    var screenheight = NS.height;
    var height = document.body.clientHeight;

    var m_mainheight = screenheight - 72;

    var mainwidth = screenwidth - 235;

    if (document.getElementById("fleftdiv").style.display == "none") {
        mainwidth = screenwidth;
    }

    document.getElementById("fmain").width = mainwidth + "px";
    document.getElementById("fmap").width = mainwidth + "px";
    document.getElementById("fexplore").width = mainwidth + "px";
    document.getElementById("fStatistics").width= mainwidth +"px";
    if (height < screenheight) {
        document.getElementById("fleft").height = m_mainheight + "px";
        document.getElementById("fmain").height = m_mainheight + "px";
        document.getElementById("fmap").height = m_mainheight + "px";
        document.getElementById("fexplore").height = m_mainheight + "px";
        document.getElementById("fStatistics").height=m_mainheight+"px";
    }
}
//---------------------------页面自适应----------------------------------------------



function loadiframe() {
    var iframe = document.getElementById('fmap')
    iframe.src = '/MapServer/Portal/3DViewer.html?mode=default'
    iframe.onload = function () {
        iframe = document.getElementById('FnaturalResources')
        iframe.src = '/BasePlatform/SmartStatistics/NaturalResources.html'
        iframe.onload = function () {
            iframe = document.getElementById('fmain')
            iframe.src = '/BasePlatform/DataServer/CatalogMain.html'
            iframe.onload = function () {
                iframe = document.getElementById('dataStanding')
                //iframe.src = '/BasePlatform/SmartStatistics/dataStanding.html'
                iframe.src = '/BasePlatform/DataResourceLedger/SearchLedger.html'
                iframe.onload = function () {
                    iframe = document.getElementById('devopsCentre')
                    iframe.src = '/BasePlatform/SmartStatistics/devopsCentre.html'
                    iframe.onload = function () {
                        iframe = document.getElementById('applicationAnalyse')
                        iframe.src = '/BasePlatform/SmartStatistics/applicationAnalyse.html'
                        iframe.onload = function () {
                            iframe = document.getElementById('fexplore')
                            iframe.src = '/BasePlatform/SmartStatistics/BasicStaticsNew.html'
                            iframe.onload = function () {
                                iframe = document.getElementById('fStatistics')
                                iframe.src = '/BasePlatform/SmartStatistics/StatisticalAnalysis.html'
                            }
                        }
                    }
                }
            }
        }
    }
}

//功能模块点击交互
function SelectHeaderMainTab(tabindex) {
    $(".header_tab.selected").removeClass("selected");
    $(".header_tab.header_tab" + tabindex).addClass("selected");
    parent.window.document.getElementById('fmap').style.display = "none";
    parent.window.document.getElementById('fmain').style.display = "none";
    // parent.window.document.getElementById('otherIframe').style.display = "none";

    // 地图 fmap
    if (tabindex == 1) {
        if(!$("#fmap").attr("src")){$("#fmap").attr("src",'/MapServer/Portal/3DViewer.html?mode=default');}
        document.getElementById('fmain').style.display = "none"; 
        document.getElementById('fmap').style.display = "block"; 
        document.getElementById('fexplore').style.display = "none";  
        document.getElementById('dataStanding').style.display = "none"; 
        document.getElementById('devopsCentre').style.display="none";  
        document.getElementById('applicationAnalyse').style.display = "none";  
        document.getElementById('resourcesRegulation').style.display="none";  
        document.getElementById('developmentCenter').style.display = "none";  
        document.getElementById('applicationCenter').style.display = "none";  
        document.getElementById('personalWorkbench').style.display = "none";  
        document.getElementById('nameZx').className = ''
        document.getElementById('userName').className = ''
    }
    // 云服务管理 FnaturalResources
    else if (tabindex == 2) {  
        if(!$("#FnaturalResources").attr("src")){$("#FnaturalResources").attr("src",'/BasePlatform/SmartStatistics/NaturalResources.html');}
        document.getElementById('FnaturalResources').style.display = ""; 
        document.getElementById('fmain').style.display = "none"; 
        document.getElementById('fmap').style.display = "none"; 
        document.getElementById('fexplore').style.display = "none";   
        document.getElementById('dataStanding').style.display = "none";  
        document.getElementById('devopsCentre').style.display="none"; 
        document.getElementById('applicationAnalyse').style.display = "none";  
        document.getElementById('resourcesRegulation').style.display="none";  
        document.getElementById('developmentCenter').style.display = "none";  
        document.getElementById('applicationCenter').style.display = "none";  
        document.getElementById('personalWorkbench').style.display = "none";  
        document.getElementById('nameZx').className = ''
        document.getElementById('userName').className = ''
    } 
    // 探索挖掘
    else if (tabindex == 3) {
        if(!$("#fexplore").attr("src")){$("#fexplore").attr("src",'/BasePlatform/SmartStatistics/BasicStaticsNew.html');}
        document.getElementById('FnaturalResources').style.display = "none"; 
        document.getElementById('fmain').style.display = "none"; 
        document.getElementById('fmap').style.display = "none"; 
        document.getElementById('fexplore').style.display = "";   
        document.getElementById('dataStanding').style.display = "none";  
        document.getElementById('devopsCentre').style.display="none";  
        document.getElementById('applicationAnalyse').style.display = "none";   
        document.getElementById('resourcesRegulation').style.display="none";  
        document.getElementById('developmentCenter').style.display = "none";  
        document.getElementById('applicationCenter').style.display = "none";  
        document.getElementById('personalWorkbench').style.display = "none";  
        document.getElementById('nameZx').className = ''
        document.getElementById('userName').className = ''
    }
    // 数据资源台账
    else if (tabindex == 4) {
        // if(!$("#dataStanding").attr("src")){$("#dataStanding").attr("src",'/BasePlatform/DataResourceLedger/SearchLedger.html');}
        $("#dataStanding").attr("src",'/BasePlatform/DataResourceLedger/SearchLedger.html');
        document.getElementById('FnaturalResources').style.display = "none"; 
        document.getElementById('fmain').style.display = "none"; 
        document.getElementById('fmap').style.display = "none"; 
        document.getElementById('fexplore').style.display = "none";   
        document.getElementById('dataStanding').style.display = "";  
        document.getElementById('devopsCentre').style.display="none"; 
        document.getElementById('applicationAnalyse').style.display = "none";   
        document.getElementById('resourcesRegulation').style.display="none";  
        document.getElementById('developmentCenter').style.display = "none";  
        document.getElementById('applicationCenter').style.display = "none";  
        document.getElementById('personalWorkbench').style.display = "none";  
        document.getElementById('nameZx').className = ''
        document.getElementById('userName').className = ''
    }
    //统计分析
    else if(tabindex ==5){  
        if(!$("#devopsCentre").attr("src")){$("#devopsCentre").attr("src",'/BasePlatform/SmartStatistics/devopsCentre.html');}
        document.getElementById('FnaturalResources').style.display = "none"; 
        document.getElementById('fmain').style.display = "none"; 
        document.getElementById('fmap').style.display = "none"; 
        document.getElementById('fexplore').style.display = "none";  
        document.getElementById('dataStanding').style.display = "none";  
        document.getElementById('devopsCentre').style.display="";  
        document.getElementById('resourcesRegulation').style.display="none";  
        document.getElementById('developmentCenter').style.display = "none";  
        document.getElementById('applicationCenter').style.display = "none";  
        document.getElementById('personalWorkbench').style.display = "none";  
        document.getElementById('nameZx').className = ''
        document.getElementById('userName').className = ''
    } 
    // 应用分析
    else if (tabindex ==6) { 
        if(!$("#applicationAnalyse").attr("src")){$("#applicationAnalyse").attr("src",'/BasePlatform/SmartStatistics/applicationAnalyse.html');}
        document.getElementById('FnaturalResources').style.display = "none"; 
        document.getElementById('fmain').style.display = "none"; 
        document.getElementById('fmap').style.display = "none"; 
        document.getElementById('fexplore').style.display = "none";   
        document.getElementById('dataStanding').style.display = "none";  
        document.getElementById('devopsCentre').style.display="none";  
        document.getElementById('applicationAnalyse').style.display = "";   
        document.getElementById('resourcesRegulation').style.display="none";  
        document.getElementById('developmentCenter').style.display = "none";  
        document.getElementById('applicationCenter').style.display = "none";  
        document.getElementById('personalWorkbench').style.display = "none";  
        document.getElementById('nameZx').className = ''
        document.getElementById('userName').className = ''
    }
    // applicationCenter  
    else if (tabindex == 7) {  
        // if(!$("#applicationCenter").attr("src")){$("#applicationCenter").attr("src",'/BasePlatform/SmartStatistics/ApplicationCenter.html');}
        $("#applicationCenter").attr("src",'/BasePlatform/SmartStatistics/ApplicationCenter.html');
        document.getElementById('FnaturalResources').style.display = "none"; 
        document.getElementById('fmain').style.display = "none"; 
        document.getElementById('fmap').style.display = "none"; 
        document.getElementById('fexplore').style.display = "none";  
        document.getElementById('dataStanding').style.display = "none";  
        document.getElementById('devopsCentre').style.display="none";  
        document.getElementById('resourcesRegulation').style.display="none";  
        document.getElementById('developmentCenter').style.display = "none";  
        document.getElementById('applicationCenter').style.display = "";  
        document.getElementById('personalWorkbench').style.display = "none";  
        document.getElementById('nameZx').className = ''
        document.getElementById('userName').className = ''
    }
    // resourcesRegulation 
    else if (tabindex == 8) {
        if(!$("#resourcesRegulation").attr("src")){$("#resourcesRegulation").attr("src",'/BasePlatform/Visualization/view/index.html');}
        document.getElementById('FnaturalResources').style.display = "none"; 
        document.getElementById('fmain').style.display = "none"; 
        document.getElementById('fmap').style.display = "none"; 
        document.getElementById('fexplore').style.display = "none";  
        document.getElementById('dataStanding').style.display = "none";  
        document.getElementById('devopsCentre').style.display="none";  
        document.getElementById('resourcesRegulation').style.display="";  
        document.getElementById('developmentCenter').style.display = "none";  
        document.getElementById('applicationCenter').style.display = "none";  
        document.getElementById('personalWorkbench').style.display = "none";  
        document.getElementById('nameZx').className = ''
        document.getElementById('userName').className = ''
    }
    // developmentCenter 开发中心
    else if (tabindex == 9) {
        //if(!$("#developmentCenter").attr("src")){$("#developmentCenter").attr("src",'/BasePlatform/Home/devCenter.html');}
        // if(!$("#developmentCenter").attr("src")){$("#developmentCenter").attr("src",'/BasePlatform/Api/apiDoc/api.html');}
        if(!$("#developmentCenter").attr("src")){$("#developmentCenter").attr("src",'/BasePlatform/Api/apiDoc/ApiDoc.html');}
        document.getElementById('FnaturalResources').style.display = "none"; 
        document.getElementById('fmain').style.display = "none"; 
        document.getElementById('fmap').style.display = "none"; 
        document.getElementById('fexplore').style.display = "none";  
        document.getElementById('dataStanding').style.display = "none";  
        document.getElementById('devopsCentre').style.display="none";  
        document.getElementById('resourcesRegulation').style.display="none";  
        document.getElementById('developmentCenter').style.display = "";   
        document.getElementById('applicationCenter').style.display = "none";  
        document.getElementById('personalWorkbench').style.display = "none";  
        document.getElementById('nameZx').className = ''
        document.getElementById('userName').className = ''
    } 
    //  personalWorkbench 个人工作台
    else if (tabindex == 10) {
        if(!$("#personalWorkbench").attr("src")){$("#personalWorkbench").attr("src",'BasePlatform/User/personalWorkbench.html');}
        document.getElementById('FnaturalResources').style.display = "none"; 
        document.getElementById('fmain').style.display = "none"; 
        document.getElementById('fmap').style.display = "none"; 
        document.getElementById('fexplore').style.display = "none";  
        document.getElementById('dataStanding').style.display = "none";  
        document.getElementById('devopsCentre').style.display="none";  
        document.getElementById('resourcesRegulation').style.display="none";  
        document.getElementById('developmentCenter').style.display = "none";  
        document.getElementById('applicationCenter').style.display = "none";  
        document.getElementById('personalWorkbench').style.display = "";  
        $('#lay_nav li').each(function () {
            if ($(this).hasClass('layui-this')) {
                $(this).removeClass("layui-this selected")
            }
        })
    }
}


var fleftdivWidth = $('#fleftdiv').width();
var frightdivWidth = $(window).width() - fleftdivWidth;
$('#hideBtn').css('left', fleftdivWidth + 3);
$('#hideBtn').on('click', function() {
    // TreeShows();
    if ($('#hideBtn div').hasClass('show')) {
        // 显示
        $('#hideBtn div').removeClass('show');
        $('#hideBtn').css('left', fleftdivWidth + 3);
        $('#fleftdiv').show();
        $('#frightdiv,#frightdiv iframe').width(frightdivWidth - 2 + 'px');
    } else {
        // 隐藏
        $('#hideBtn div').addClass('show');
        $('#hideBtn').css('left', 0);
        $('#fleftdiv').hide();
        $('#frightdiv,#frightdiv iframe').width('100%');
    }
});
$('#frightdiv,#frightdiv iframe').width(frightdivWidth - 2 + 'px');
$('#hideBtn').click();


function TreeShows() {
    if (document.getElementById("fleftdiv").style.display == "none") {
        // 显示
        document.getElementById("fleftdiv").style.display = "inline";
    } else {
        // 隐藏
        document.getElementById("fleftdiv").style.display = "none";
    }
    iFrameSize();
}

//处理登录信息
var username = GetUserChinaName(); //获取登录用户中文名
// var userno = GetUserNO(); //获取登录no； 
var userno = getCookie ('portaluserno')
var leftframe = document.getElementById("fleft");
var fMainNode = document.getElementById("fmain");
leftframe.setAttribute("src", ""); // ./MainListAdmin.html  
// 判断是不是科室负责人，不是的话云服务管理和运维管理隐藏 
var results = sendAjax(modelURL + "/sw/user/getUserIsManager", "POST", {
    userNo:userno
});
if (results.code == 200) {
    if (results.data.ISMANAGER == 0) {
        document.getElementById('management').style.display="none";  
        document.getElementById('operations').style.display="none";  
    }else if(results.data.ISMANAGER == 1){
        document.getElementById('operations').style.display="none";
    }
} else {
}
if (!username || username == "Guest") {
    //document.getElementById("loginlink").text = "登录";
    //document.getElementById("loginlink").href = "/";
    //document.getElementById("loginlink").style.width == "45px";
} else {
    $("#userInfoBtn").click(function(){
        window.open("src/PersonalInformation.html?id=" + userno);
    });
    $("#userInfoBtn").attr('title',username);
    $("#headerUserName a").eq(0).html(username);
    //document.getElementById("loginlink").text = username;
    //document.getElementById("loginlink").href = "src/PersonalInformation.html?id=" + userno
    //document.getElementById("loginlink").target = "fmain"; //fmain
    //document.getElementById("loginlink").style.width == "65px";
}
iFrameSize();

function sendAjax(url, type, data) {
    $.ajaxSettings.async = false;
    var results;
    $.ajax({
        type: type,
        dataType: "json",
        url: url,
        data: data,
        success: function (data) {
            results = data;
        },
        error: function (error) {
            results = error;
        }
    });
    return results;
}
//用户工具菜单展示
function fillUserServer(node, isEnter) {
    if (isEnter) {
        $("#userTools").css("display", "inherit");
        $(".header_tab.header_tab3").addClass("selected");
        $(".header_tab.selected").not(".header_tab3").addClass("pause");
    } else {
        $("#userTools").css("display", "none");
        $(".header_tab.header_tab3").removeClass("selected");
        $(".header_tab.pause").removeClass("pause");
        return;
    }
    var result = addOrRemoveServer("tools", "");
    if (result.code != "200") {
        //alert(result.msg);
        return;
    }
    $("#userTools").empty();
    var toolsData = result.data;
    var toolsData_json = {};
    toolsData_json["max"] = 1;
    var userToolsTable = null;
    if (toolsData == null) {
        userToolsTable = "<table><tr>" +
            "<td><span>规划服务</span></td>" +
            "<td><span>监管服务</span></td>" +
            "<td><span>审批服务</span></td>" +
            "<td><span>资源评价</span></td>"
            //+ "<td><span>公众查询</span></td>"
            //+ "<td><span>大数据工具</span></td>"
            +
            "</tr></table>";
        toolsData_json.max = 0;
    } else {
        for (var i = 0; i < toolsData.length; i++) {
            if (toolsData_json.hasOwnProperty(toolsData[i].SPATIAL)) {
                toolsData_json[toolsData[i].SPATIAL].push(toolsData[i]);
                if (toolsData_json[toolsData[i].SPATIAL].length > toolsData_json.max) {
                    toolsData_json.max = toolsData_json[toolsData[i].SPATIAL].length;
                }
            } else {
                toolsData_json[toolsData[i].SPATIAL] = [toolsData[i]];
            }
        }
        userToolsTable = "<table><tr>" +
            "<td><span>规划服务</span></td>" +
            "<td><span>监管服务</span></td>" +
            "<td><span>审批服务</span></td>" +
            "<td><span>资源评价</span></td>"
            //+ "<td><span>公众查询</span></td>"
            //+ "<td><span>大数据工具</span></td>"
            +
            "</tr><tr>" +
            "<td>" + getToolContent(toolsData_json.GH) + "</td>" +
            "<td>" + getToolContent(toolsData_json.JG) + "</td>" +
            "<td>" + getToolContent(toolsData_json.SP) + "</td>" +
            "<td>" + getToolContent(toolsData_json.ZYPJ) + "</td>"
            //+ "<td>" + getToolContent(toolsData_json.GZCX) + "</td>"
            //+ "<td>" + getToolContent(toolsData_json.TOOL) + "</td>"
            +
            "</tr></table>";
    }
    $("#userTools").append(userToolsTable);
    $("#userTools").height(toolsData_json.max * 30 + 80);

    //模型调用
    $("#userTools li font").click(function(e) {
        // alert('当前数据均为假数据');
        $.ajax({
            //type: 'post',
            async: false,
            // mock数据
            url: '/BasePlatform/ModelDriven/model1.json',
            //data: {},
            //datatype: 'json',
            success: function(res) {
                if (typeof(res) == 'string') {
                    res = JSON.parse(res);
                }
                console.log(res);
                if (res.code == 200) {
                    var html = `
                    <div id="form">
                        <div id="formContent">`;
                    res.data.map(function(item, index) {
                        console.log(this);
                        html += `<div id="` + item.id + `" class="formItem" comment="` + item.comment + `">
                        <label class="formLabel">` + item.name + `</label>`;
                        switch (item.formtype) {
                            case "input":
                                html += `
                                <input class="formInput" type="text" value="` + item.value + `">`;
                                break;
                            case "option":
                                html += `
                                <select class="formSelect" name="" id="">`
                                item.option.map(function(ite) {
                                    html += `<option value="` + ite + `">` + ite + `</option>`
                                });
                                html += `</select>`;
                                break;
                            case "radio":
                                html += `<ul>`;
                                item.option.map(function(ite) {
                                    html += `<li>
                                    <input class="radioInput" type="radio" name="` + item.ID + `" value="` + ite + `" title="` + ite + `">
                                    <div class="radioDiv">` + ite + `</div>
                                </li>`;
                                });
                                html += `</ul>`;
                                break;
                            case "check":
                                html += `<ul>`;
                                item.option.map(function(ite) {
                                    html += `<li>
                                    <input class="radioInput" type="checkbox" name="` + item.ID + `" value="` + ite + `" title="` + ite + `">
                                    <div class="radioDiv">` + ite + `</div>
                                </li>`;
                                });
                                html += `</ul>`;
                                break;
                            case "dataobject_local":
                                html += `<input class="formInput fileInput" type="file">`
                                break;
                            case "dataobject_sever":
                                html += `<input class="formInput fileInput" type="file">`
                                break;
                            default:
                                break;
                        }
                        html += `</div>`;
                    });
                    html += `</div>
                    </div>
                    <!-- 右侧 -->
                    <div id="comment">
                        <div id="commentContent">
                            我是描述
                        </div>
                    </div>`;
                    /////////////////////////////////////////
                    // var index = layer.open({
                    //     type: 1,
                    //     title: '符合城乡总体规划分析',
                    //     content: html,
                    //     area: '700px',
                    //     shadeClose: true, //点击遮罩关闭
                    //     btn: ['运行', '取消'],
                    // });
                    //layer.full(index);
                    $('.formItem').hover(function(e) {
                        $('#commentContent').html($(e.currentTarget).attr('comment'));
                    }, function() {
                        $('#commentContent').html('');
                    });
                } else {
                    layui.layer.msg(res.msg, {
                        shade: 0.3,
                        time: 1000 // 1秒关闭
                    });
                }
                layer.closeAll('loading');
            },
            error: function(err) {
                console.log(err);
                layer.closeAll('loading');
            }
        });
    });
}

function getToolContent(toolArray) {
    if (toolArray) {
        var toolContent = "<ul>";
        for (var i = 0; i < toolArray.length; i++) {
            toolContent += "<li title='" + toolArray[i].NAME + "' guid='" + toolArray[i].RESOURCEID + "' onmouseenter=addDeleteBtn(this,true) onmouseleave=addDeleteBtn(this,false)><font>" + toolArray[i].NAME + "</font></li>";
        } //
        toolContent += "</ul>";
        return toolContent;
    } else {
        return "";
    }
}
//li标签添加删除按钮
function addDeleteBtn(node, isAdd) {
    if (isAdd) {
        var deleteBtn = "<span title='移除工具' onclick='removeUserTool(this)'>×</span>";
        $(node).append(deleteBtn);
    } else {
        $(node).find("span").remove();
    }
}
//移除用户工具
function removeUserTool(node) {
    var guid = $(node).parent().attr("guid");
    var result = addOrRemoveServer("delete", guid);
    if (result.code == "200") {
        $(node).parent().remove();
    }
    alert(result.msg);
    //console.log(guid);
}


//var mouseOnTab = false;
//var mouseOnTools = false;

//if (node=="tab") {
//    if (isEnter) {
//        mouseOnTab = true;
//    }
//    else {
//        mouseOnTab = false;
//    }
//}
//else if (node=="tools") {
//    if (isEnter) {
//        mouseOnTools = true;
//    }
//    else {
//        mouseOnTab = false;
//    }
//}

//console.log("tab," + mouseOnTab);
//console.log("tools," + mouseOnTools);
//if (openStatus) {
//    $(node).find("#userTools").css("display", "inherit");
//    var result = addOrRemoveServer("tools", "");
//    console.log(result);
//}
//else {
//    $(node).css("display", "none");
//}

function setModel(){
    var model = getQueryString("model");
    if(model){
        $('#lay_nav li').each(function () {
            $(this).click(function (){
                console.log("dianji");
            })
            if ($(this).hasClass('layui-this')) {
                $(this).removeClass("layui-this selected")
            }
        })
        switch(model){
            case "analyse":
                $($('#lay_nav li')[2]).addClass("layui-this selected")
                SelectHeaderMainTab(7);
                break;
        }
    }
}
  
/**
 * 主页新加
 */
$(function() {
    var $fleft = $('#fleft')[0];
    var $fmain = $('#fmain')[0];

    if ($fmain.attachEvent) {
        $fmain.attachEvent("onload", function() {
            main();
        });
    } else {
        $fmain.onload = function() {
            main();
        };
    }

    var loaded = false;

    function main() {
        if (!loaded) {
            loaded = true;
            setTimeout(function() {
                showFirst();
                clickSpecial();
            }, 2000);
        }
    }

    /**
     * 左侧树默认打开第一项
     */
    function showFirst() {
        var $treeview = $('#fleft').contents().find('#sidebarmenu .treeview').eq(0);
        if (!$treeview.hasClass('menu-open')) {
            // $treeview.find('a').eq(0).click();
            $treeview.addClass('menu-open');
            $treeview.find('ul').show();
        }
    }

    /**
     * 点击专题应用服务地图tab名称联动
     */
    function clickSpecial() {
        var $treeview;
        $('#fleft').contents().find('#sidebarmenu .treeview>a').each(function() {
            var $this = $(this);
            if ($this.attr('onclick') == 'SetFmainSrc(200)') {
                $treeview = $this.parent();
                $treeview.find('.treeview-menu li font').on('click', function() {
                    $('#header_tab2').html('<img src="/img/maintab/map.png" width="22px" style="margin-right: 6px; top: -2px; position: relative">' + $(this).html())
                })
                return;
            }
        });
    };

    /* 模型监控显示收起 */
    $('#showModelDrivenList').on('click', function() {
        var $this = $(this);
        if ($('#ModelDrivenList_d').width() != 0) {
            $('#ModelDrivenList_d').animate({
                width: '0',
            });
            $this.animate({
                right: 0
            });
            $this.find('.myShowTabIcon').removeClass('rotate');
        } else {
            $('#ModelDrivenList_d').animate({
                width: '420px',
            });
            $this.animate({
                right: '420px'
            });
            $this.find('.myShowTabIcon').addClass('rotate');
            var url = window.parent.$('#ModelDrivenList_d').attr('src');
            window.parent.$('#ModelDrivenList_d').attr('src', url);
        }
    });

    //$('#showModelDrivenList').on('mouseenter', function() {
    //    if ($('#ModelDrivenList_d').width() !== 0) {
    //        return;
    //    }
    //    $('#ModelDrivenList_d').animate({
    //        width: '420px',
    //    });
    //    $('#showModelDrivenList').animate({
    //        right: '420px'
    //    });
    //    // window.parent.$('#ModelDrivenList_d').contents().find('#refreshBtn').click();
    //    var url = window.parent.$('#ModelDrivenList_d').attr('src');
    //    window.parent.$('#ModelDrivenList_d').attr('src', url);
    //})
    //$('#ModelDrivenList_d').on('mouseleave', function() {
    //    $('#ModelDrivenList_d').animate({
    //        width: '0',
    //    });
    //    $('#showModelDrivenList').animate({
    //        right: 0
    //    });
    //})

    /* 数据分析显示收起 */
    $('#analyseTab').on('click', function() {
        var $this = $(this);
        if ($('#analyseContent').width() != 0) {
            $('#analyseContent').animate({
                width: '0',
            });
            $this.animate({
                right: 0
            });
            $this.find('.myShowTabIcon').removeClass('rotate');
        } else {
            $('#analyseContent').animate({
                width: '340px',
            });
            $this.animate({
                right: '340px'
            });
            $this.find('.myShowTabIcon').addClass('rotate');
        }
    });

    $('#analyseTab').on('mouseenter', function() {
        if ($('#analyseContent').width() !== 0) {
            return;
        }
        $('#analyseContent').animate({
            width: '340px',
        });
        $('#analyseTab').animate({
            right: '340px'
        });
    })
    $('#analyseContent').on('mouseleave', function() {
        $('#analyseContent').animate({
            width: '0',
        });
        $('#analyseTab').animate({
            right: '0'
        });
    })
    setModel();


    /*统计分析显示收起*/
    $('#statisticsTab').on('click', function() {
        var $this = $(this);
        if ($('#statisticsContent').width() != 0) {
            $('#statisticsContent').animate({
                width: '0',
            });
            $this.animate({
                right: 0
            });
            $this.find('.myShowTabIcon').removeClass('rotate');
        } else {
            $('#statisticsContent').animate({
                width: '340px',
            });
            $this.animate({
                right: '340px'
            });
            $this.find('.myShowTabIcon').addClass('rotate');
        }
    });
    $('#statisticsTab').on('mouseenter', function() {
        if ($('#statisticsContent').width() !== 0) {
            return;
        }
        $('#statisticsContent').animate({
            width: '340px',
        });
        $('#statisticsTab').animate({
            right: '340px'
        });
    })
    $('#statisticsContent').on('mouseleave', function() {
        $('#statisticsContent').animate({
            width: '0',
        });
        $('#statisticsTab').animate({
            right: '0'
        });
    })


    /* 数据探索显示收起 */
    $('#dataExploreTab').on('click', function() {
        var $this = $(this);
        if ($('#dataExploreContent').width() != 0) {
            $('#dataExploreContent').animate({
                width: '0',
            });
            $this.animate({
                right: 0
            });
            $this.find('.myShowTabIcon').removeClass('rotate');
        } else {
            $('#dataExploreContent').animate({
                width: '340px',
            });
            $this.animate({
                right: '340px'
            });
            $this.find('.myShowTabIcon').addClass('rotate');
        }
    });

    $('#dataExploreTab').on('mouseenter', function() {
        if ($('#dataExploreContent').width() !== 0) {
            return;
        }
        $('#dataExploreContent').animate({
            width: '340px',
        });
        $('#dataExploreTab').animate({
            right: '340px'
        });
    })
    $('#dataExploreContent').on('mouseleave', function() {
        $('#dataExploreContent').animate({
            width: '0',
        });
        $('#dataExploreTab').animate({
            right: '0'
        });
    })



    // $(document).click(function(){
    //     $('#ModelDrivenList_d, #analyseContent, #dataExploreContent').css({
    //         width: '0px'
    //     });
    // });
    // $('#ModelDrivenList_d, #analyseContent, #dataExploreContent').click(function(event){
    //     event.stopPropagation();
    // });

    // $('#ModelDrivenList_d, #analyseContent, #dataExploreContent').focus(function () {
    //     debugger
    //     var $this = $(this);
    //     if ($this.width() != 0) {
    //         $this.prev().click();
    //     }
    // });
    // $('#ModelDrivenList_d, #analyseContent, #dataExploreContent').blur(function () {
    //     debugger
    //     var $this = $(this);
    //     if ($this.width() != 0) {
    //         $this.prev().click();
    //     }
    // });

    /**
     * 数据分析获取内容
     */
    function getToolContentNew(obj) {
        var html = '<ul style="width: 100%;" class="">';
        if (obj) {
            obj.forEach(function(item, index) {
                html += `
                <li class="content">
                    <span class="icon"></span>
                    <div class = "ellipsis" onclick = "showModelDriven('` + item.NAME + `')" title = "` + item.NAME + `" > ` + item.NAME + `</div>`
                html += `<button class="deleteBtn" guid="` + item.RESOURCEID + `" style="float: left;"></button>`
                if (item.SERVERLAYERGUID) {
                    html += `<button class="dingwei" style="float: right; background-image: url(Mapserver/Images/LayerManage/LayerTree/icon_server.png)" SERVERLAYERGUID="` + item.SERVERLAYERGUID + `" SERVERLAYERZOOM="` + item.SERVERLAYERZOOM + `"></button>`
                }
                html += `</li>`;
            });
        }
        html += '</ul>';
        return html;
    }
    window.addOrRemoveServerInit = function() {
        addOrRemoveServer("tools", "", function(result) {
            if (result.code != "200") {
                //alert(result.msg);
                return;
            }
            var toolsData = result.data;
            var toolsData_json = {};
            toolsData_json["max"] = 1;
            if (toolsData == null) {
                toolsData_json.max = 0;
            } else {
                for (var i = 0; i < toolsData.length; i++) {
                    if (toolsData_json.hasOwnProperty(toolsData[i].SPATIAL)) {
                        toolsData_json[toolsData[i].SPATIAL].push(toolsData[i]);
                        if (toolsData_json[toolsData[i].SPATIAL].length > toolsData_json.max) {
                            toolsData_json.max = toolsData_json[toolsData[i].SPATIAL].length;
                        }
                    } else {
                        toolsData_json[toolsData[i].SPATIAL] = [toolsData[i]];
                    }
                }
            }
            var html = `
                <ul style="width: 100%;">
                    <li class="levelTwoTitle">
                        <span class="icon"></span>全部<span class="arrow"></span>` +
                getToolContentNew(toolsData_json.ALL) +
                `</li>
                    <li class="levelTwoTitle">
                        <span class="icon"></span>规划<span class="arrow"></span>` +
                getToolContentNew(toolsData_json.GH) +
                `</li>
                    <li class="levelTwoTitle">
                        <span class="icon"></span>监管<span class="arrow"></span>` +
                getToolContentNew(toolsData_json.JG) +
                `</li>
                    <li class="levelTwoTitle">
                        <span class="icon"></span>审批<span class="arrow"></span>` +
                getToolContentNew(toolsData_json.SP) +
                `</li>
                    <li class="levelTwoTitle">
                        <span class="icon"></span>资源评价<span class="arrow"></span>` +
                getToolContentNew(toolsData_json.ZYPJ) +

                `</li>
                    <li class="levelTwoTitle">
                        <span class="icon"></span>通用应用服务<span class="arrow"></span>` +
                getToolContentNew(toolsData_json.TY) +
                `</li>
                    <li class="levelTwoTitle">
                        <span class="icon"></span>专题图制作服务<span class="arrow"></span>` +
                getToolContentNew(toolsData_json.ZT) +
                `</li>
                </ul>
            `;
            $('#analyseContent .myShowContainer').html(html);
        });
    }
    // addOrRemoveServerInit();

    // 点击数据分析下二级标题
    $('#analyseContent').on('click', '.levelTwoTitle', function(e) {
        var $this = $(this);
        if (!$(e.target).hasClass('levelTwoTitle') && !$(e.target).hasClass('arrow')) {
            return
        }
        if ($this.find('ul').is(':hidden')) {
            $this.find('ul').slideDown();
            $this.find('.arrow').css({
                transform: 'rotate(0deg)'
            })
        } else {
            $this.find('ul').slideUp();
            $this.find('.arrow').css({
                transform: 'rotate(-90deg)'
            })
        }
    });
    // 删除按钮
    $('#analyseContent').on('click', '.deleteBtn', function() {
            var $this = $(this);
            if (confirm('是否要移除当前工具?')) {
                var result = addOrRemoveServer("delete", $this.attr('guid'));
                setTimeout(function() {
                    if (result.code == "200") {
                        $this.parent().remove();
                    }
                    setTimeout(function() {
                        alert(result.msg);
                    }, 100);
                }, 200);
            }
        })
    // 定位按钮
    $('#analyseContent, #dataExploreContent').on('click', '.dingwei', function() {
        var $this = $(this);
        $('#fmap')[0].contentWindow.other_layerLocation({
            "layerGuid": $this.attr('SERVERLAYERGUID'),
            "isZoom": $this.attr('SERVERLAYERZOOM') == '0' ? false : true
        });
    })

    /* 数据探索获取内容 */
    window.getUserDataNameList = function(where) {
        $('#dataExploreContent .myShowContainer').html('');
        $.ajax({
            type: 'post',
            async: false,
            url: '/BaseAshx/SmartStatistics/ExploreDataNew.ashx',
            data: {
                mtype: 'ExploreData_GetUserDataNameList',
                where: where || '',
            },
            datatype: 'json',
            success: function(res) {
                if (typeof res == 'string') {
                    res = JSON.parse(res);
                }

                if (res.code == '200') {
                    var html = `<ul style="width: 100%;">`
                    res.data.forEach(function(item, index) {
                        var id = item.ID,
                            name = item.NAME;
                        html += ` 
                    <li class="content" guid="` + id + `">
                        <span class="icon"></span>` +
                            `<div class="ellipsis" onclick="clickDataExplor(this)" USERNO="` + item.USERNO + `" guid="` + id + `" title="` + item.NAME + `" > ` + item.NAME +
                            ` </div>`;
                        if (item.USERNO !== "admin" || userno == 'admin') {
                            html += `<button class="deleteBtn" guid="` + id + `"></button>`
                        }

                        if (item.LAYERGUID) {
                            html += `<button class="dingwei" style="float: right; background-image: url(Mapserver/Images/LayerManage/LayerTree/icon_server.png)" SERVERLAYERGUID="` + item.LAYERGUID + `" SERVERLAYERZOOM="` + item.ISZOOM + `"></button>`
                        }
                        html += `</li>`;
                    })
                    html += `</ul>`;
                    $('#dataExploreContent .myShowContainer').html(html);
                } else {
                    //alert(res.msg);
                }
            },
            error: function(err) {
                console.log(err);
                if (err.status == 405)
                    top.location.href = '/';
            }
        });
    }
    // getUserDataNameList();

    window.clickDataExplor = function(dom) {
        var id = $(dom).attr('guid');
        // location.href = '/BasePlatform/SmartStatistics/BasicStaticsNew.html?id=' + id;

        if (id) {
            var url = '/BasePlatform/SmartStatistics/BasicStaticsNew.html?id=' + id;
            $('#fexplore').attr('src', url);
        }
        $('#header_tab4,#dataExploreTab').click();
    }

    // 数据探索搜索
    $('#dataExploreSearchBtn').on('click', function() {
        var value = $('#dataExploreSearchInput').val();
        // getUserDataNameList(value)
    })

    // 删除按钮
    $('#dataExploreContent').on('click', '.deleteBtn', function() {
        var $this = $(this);
        var id = $this.attr('guid')
        if (confirm('是否要移除当前数据探索?')) {

            $.ajax({
                type: 'post',
                async: false,
                url: '/BaseAshx/SmartStatistics/ExploreDataNew.ashx',
                data: {
                    mtype: 'ExploreData_DeleteSerializeInfo',
                    id: id
                },
                datatype: 'json',
                success: function(result) {
                    if (typeof(result) == 'string') {
                        result = JSON.parse(result);
                    };
                    if (result.code == "200") {
                        $this.parent().remove();
                        setTimeout(function() {
                            alert(result.msg);
                        }, 100);
                    } else {
                        alert('删除失败');
                    }
                },
                error: function(err) {
                    console.log(err);
                }
            });
        }
    })

    window.searchFiles = function() {
        var fso = new ActiveXObject("Scripting.FileSystemObject");
        var f = fso.GetFolder(document.all.fixfolder.value);
        var fc = new Enumerator(f.files);
        var s = "";
        //以下内容是显示文件名
        for (; !fc.atEnd(); fc.moveNext()) {
            document.write(fc.item() + "<br>");
        }
        //以下内容是显示目录名
        fk = new Enumerator(f.SubFolders);
        for (; !fk.atEnd(); fk.moveNext()) {
            document.write(fk.item() + "<br>");
        }
    }
   
        //统计分析数据展示
    
        function getContentNew(obj) {
        var html = '<ul style="width: 100%;" class="">';
        if (obj) {
            obj.forEach(function(item, index) {
                html += `
                <li class="content">
                    <span class="icon"></span>
                    <div class = "ellipsis" onclick = "showStatisticsTable('` + item.NAME + `')" title = "` + item.NAME + `" > ` + item.NAME + `</div>`   
                html += `</li>`;
                    });
                }
        html += '</ul>';
        return html;
        }
     var datatreeStr = '[{"FK_EMP":"admin","WEBPATH":"Statics2.png","PNAME":"基础数据统计","NAME":"土地利用现状一级分类汇总","URL":"/pages/statistics/K1new.html?xzq=4509"},' +
            '{"FK_EMP":"admin","WEBPATH":"Statics2.png","PNAME":"基础数据统计","NAME":"土地利用现状分类面积汇总","URL":"/pages/statistics/K2new.html?xzq=4509"},' +
            '{"FK_EMP":"admin","WEBPATH":"Statics2.png","PNAME":"基础数据统计","NAME":"土地利用现状一级分类面积按权属性质汇总","URL":"/pages/statistics/K3.html?xzq=4509"},'+
            '{"FK_EMP":"admin","WEBPATH":"Statics2.png","PNAME":"基础数据统计","NAME":"城镇村及工矿用地面积汇总表","URL":"/pages/statistics/K4new.html?xzq=4509"},' +
            '{"FK_EMP":"admin","WEBPATH":"Statics2.png","PNAME":"基础数据统计","NAME":"耕地坡度分级面积汇总","URL":"/pages/statistics/K5new.html?xzq=4509"},' +
            '{"FK_EMP":"admin","WEBPATH":"Statics2.png","PNAME":"基础数据统计","NAME":"耕地种植类型面积统计","URL":"/pages/statistics/K6new.html?xzq=4509"},'+
            '{"FK_EMP":"admin","WEBPATH":"Statics2.png","PNAME":"基础数据统计","NAME":"废弃与垃圾填埋细化标注汇总统计","URL":"/pages/statistics/K17.html?xzq=4509"},'+
            '{"FK_EMP":"admin","WEBPATH":"Statics2.png","PNAME":"基础数据统计","NAME":"即可恢复与工程恢复种植属性汇总统计","URL":"/pages/statistics/K18.html?xzq=4509"},'+
            '{"FK_EMP":"admin","WEBPATH":"Statics2.png","PNAME":"基础数据统计","NAME":"林区范围内园地汇总统计","URL":"/pages/statistics/K7new.html?xzq=4509"},'+
            '{"FK_EMP":"admin","WEBPATH":"Statics2.png","PNAME":"基础数据统计","NAME":"灌丛草地汇总情况统计","URL":"/pages/statistics/K8new.html?xzq=4509"},'+
            '{"FK_EMP":"admin","WEBPATH":"Statics2.png","PNAME":"基础数据统计","NAME":"工业仓储用地按类型汇总统计","URL":"/pages/statistics/K9new.html?xzq=4509"},'+
            '{"FK_EMP":"admin","WEBPATH":"Statics2.png","PNAME":"基础数据统计","NAME":"可调整地类面积汇总","URL":"/pages/statistics/K10new.html?xzq=4509"},'+
            '{"FK_EMP":"admin","WEBPATH":"Statics2.png","PNAME":"基础数据统计","NAME":"部分细化地类面积汇总","URL":"/pages/statistics/K11new.html?xzq=4509"},'+
            '{"FK_EMP":"admin","WEBPATH":"Statics2.png","PNAME":"基础数据统计","NAME":"耕地细化调查情况统计","URL":"/pages/statistics/K12new.html?xzq=4509"},' +
            '{"FK_EMP":"admin","WEBPATH":"Statics2.png","PNAME":"基础数据统计","NAME":"批准未建设的建设用地用途情况统计","URL":"/pages/statistics/K13new.html?xzq=4509"},' +
            '{"FK_EMP":"admin","WEBPATH":"Statics2.png","PNAME":"基础数据统计","NAME":"批准未建设的建设用地现状情况统计","URL":"/pages/statistics/K14new.html?xzq=4509"},' +
            '{"FK_EMP":"admin","WEBPATH":"Statics2.png","PNAME":"基础数据统计","NAME":"永久基本农田现状情况统计","URL":"/pages/statistics/K15new.html?xzq=4509"}]';         
     var datatreeStr1='[{"FK_EMP":"admin","WEBPATH":"Statics3.png","PNAME":"专题数据统计","NAME":"三大类统计","URL":"/src/dataanalysisservice/zhuanxiangtongji/threetypes.html?xzq=4509"}]';
      var treedata = JSON.parse(datatreeStr);
      var  treedata1= JSON.parse(datatreeStr1);
      var  html1='<ul style="width: 100%;">'+
             ' <li class="levelTwoTitle">'+
                  '<span class="icon"></span>基础数据统计<span class="arrow"></span>' +
                  getContentNew(treedata) +
            '</li>'+
              '<li class="levelTwoTitle">'+
              '<span class="icon"></span>专题数据统计<span class="arrow"></span>' +
                  getContentNew(treedata1) +
              '</li>'+
              '</ul>';
         $('#statisticsContent .myShowContainer').html(html1);

       // 点击统计分析下二级标题
    $('#statisticsContent').on('click', '.levelTwoTitle', function(e) {
        var $this = $(this);
        if (!$(e.target).hasClass('levelTwoTitle') && !$(e.target).hasClass('arrow')) {
            return
        }
        if ($this.find('ul').is(':hidden')) {
            $this.find('ul').slideDown();
            $this.find('.arrow').css({
                transform: 'rotate(0deg)'
            })
        } else {
            $this.find('ul').slideUp();
            $this.find('.arrow').css({
                transform: 'rotate(-90deg)'
            })
        }
        });

});